package com.biqee.job;

import org.apache.log4j.Logger;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.scheduling.quartz.QuartzJobBean;

import com.biqee.service.crawler.BqIndexBuilder;
import com.biqee.util.EnvUtil;

public class StaticIndexJob extends QuartzJobBean {
	private static final Logger logger = Logger.getLogger(JuHuaSuanTimeStatusParseJob.class);
	
	private boolean isRunning = false;
	
	private BqIndexBuilder bqIndexBuilder; 
	
	@Override
	protected void executeInternal(JobExecutionContext context)
			throws JobExecutionException {
		if(!EnvUtil.isTaskServer()) {
			logger.info("task not run because this server is not task server");
			return;
		}
		
		if(isRunning) {
			return;
		}

		logger.info("start of static index  ");
		isRunning = true;
		try {
			bqIndexBuilder.build("http://www.biqee.com/biqee/homepage!index.jspa");
		} catch (Exception ex) {
			logger.error("parse failed! ", ex);
		}

		logger.info("end of static index");
		isRunning = false;
	}

	public void setBqIndexBuilder(BqIndexBuilder bqIndexBuilder) {
		this.bqIndexBuilder = bqIndexBuilder;
	}
	
	
	
}
